<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">

    </div>
    <script src="./src/react.js"></script>
    <script src="./src/react-dom.js"></script>
    <script src="./src/babel.js"></script>
    <script type="text/babel">

        class Tab extends React.Component {
            constructor() {
                super(),
                this.state={
                    flag:1,
                    con: <div>第一项内容</div>
                }
            }
            changeTab = (n) => {
                // console.log(n);
                this.setState({
                    flag: n,
                })
                switch (n) {
                    case 1:
                        this.setState({
                            con: <div>第一项内容</div>
                        })
                        break;
                    case 2:
                        this.setState({
                            con: <div>第二项内容</div>
                        })
                        break;
                    case 3:
                        this.setState({
                            con: <div>第三项内容</div>
                        })
                        break;
                    default:
                        this.setState({
                            con: <div>第一项内容</div>
                        })
                        break;
                }
            }
            render() {
                return (
                    <div>
                        <ul>
                            <li className={this.state.flag == 1 ? 'active' : ''}
                                onClick={() => this.changeTab(1)}
                            >选项一</li>
                            <li className={this.state.flag == 2 ? 'active' : ''}
                                onClick={() => this.changeTab(2)}
                            >选项二</li>
                            <li className={this.state.flag == 3 ? 'active' : ''}
                                onClick={() => this.changeTab(3)}
                            >选项三</li>
                        </ul>

                        <div>

                            {this.state.con}
                        </div>
                    </div>
                )
            }
        }
        ReactDOM.render(
            <Tab></Tab>,
            document.getElementById("app")
        )
    </script>
</body>

</html>